package com.kedacom.demo.spring.websocket.server;

import org.springframework.stereotype.Controller;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;

import com.kedacom.demo.spring.websocket.AbstractWebSocketServerHandler;

@Controller("myWebSocketHandler")
public class MyWebSocketHandler extends AbstractWebSocketServerHandler {

	@Override
	protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
		super.handleTextMessage(session, message);

		// TODO: 处理收到消息后的业务逻辑
		String text = message.getPayload();

		// TODO: 这里演示了群发消息，并不是实际的业务场景
		for (WebSocketSession s : sessions) {
			s.sendMessage(new TextMessage(text));
		}
	}

}
